from django.shortcuts import render,HttpResponse
from orm import models

# Create your views here.


def orm(request):
	# obj = models.UserGroup.objects.filter(id="2").first()  #这类型获取对象，直接获取到可以不断.出其他外键关联表的数据
	# print(obj.name,obj.gender,obj.user_caption.caption,obj.user_level.level,obj.user_level.user_level.leveltype)

	#这里要注意了,跟以前的values出的方式是一样的， 只是要帅选其他外键表的字段，引用他们的时候需要用  __  来进行引用，这里是关键！
	# obj= models.UserGroup.objects.filter(id__gt=0).values('name','gender','user_caption__caption','user_level__level','user_level__user_level__leveltype')
	# for row in obj:
	# 	print(row['name'],row['gender'],row['user_caption__caption'],row['user_level__level'],row['user_level__user_level__leveltype'])

	#同上，但这个QuerySet存的是元祖
	# obj = models.UserGroup.objects.filter(id__gt=0).values_list('name', 'gender', 'user_caption__caption','user_level__level', 'user_level__user_level__leveltype')
	# for row in obj:
	# 	print(row[0],row[1],row[2],row[3],row[4])

	# models.UserGroup.objects.create(name='Mox',tel='12390485672',passwd='123456',email='3543@163.com',gender='2',user_caption_id='2',user_level_id='2')
	return HttpResponse('OK')